package com.hrm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrm.mapper.EmployeeMapper;
import com.hrm.pojo.DTO.EmployeeDTO;
import com.hrm.pojo.DTO.EmployeeVO;
import com.hrm.pojo.Employee;
import com.hrm.service.EmployeeService;
import com.hrm.utils.entity.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    /**
     * 员工查询
     * @param employeeDTO
     * @return
     */
    public PageResult<EmployeeVO> page(EmployeeDTO employeeDTO) {
        //开启分页
        Page<EmployeeVO> pageEmployee  = PageHelper.startPage(employeeDTO.getPage(), employeeDTO.getPageSize());
        List<EmployeeVO> list = employeeMapper.selectBySomething(employeeDTO);
        return new PageResult<EmployeeVO>(pageEmployee.getTotal(),list);
    }

    /**
     * 添加员工
     * @param employee
     * @return
     */
    public Boolean insert(Employee employee) {
        return  employeeMapper.insertSelective(employee)>0;
    }

    /**
     * 修改员工
     * @param employee
     * @return
     */
    public Boolean updateById(Employee employee) {
        return employeeMapper.updateByPrimaryKeySelective(employee)>0;
    }

    /**
     * 删除员工
     * @param id
     * @return
     */
    public Boolean deleteById(Integer id) {
        return employeeMapper.deleteByPrimaryKey(id)>0;
    }
}
